<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>
            X-admin v1.0
        </title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="/static/css/x-admin.css" media="all">
    </head>
    
    <body>
        <div class="x-body">
            <form class="layui-form" action='<{:Url("admin/FoodCity/update")}>' method="POST" >
                <div id="hidenImage">
                    {foreach $foodCity.imgUrl as $url }
                    <input type="hidden" name="imgUrl[]" class="hidImg" onclick='delImg(this, "<{$url}>")' value="<{$url}>">
                    {/foreach}
                </div>
                <input type="hidden" name="id" value="<{$foodCity.id}>">
                <div class="layui-form-item">
                    <label for="title" class="layui-form-label">
                        <span class="x-red">*</span>描述
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="title" name="title" required="" lay-verify="required" value="<{$foodCity.title}>"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="role" class="layui-form-label">
                        <span class="x-red">*</span>城市
                    </label>
                    <div class="layui-input-inline">
                        <select name="cityId" required="" lay-verify="required">
                            <option value="">选择城市</option>
                            {foreach $citys as $city}
                            <option value="<{$city.id}>"
                                    {if condition="$foodCity.cid == $city.id"}
                                    selected=""
                                    {/if}
                            ><{$city.city}></option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="images" class="layui-form-label">
                        <span class="x-red">*</span>展示图
                    </label>
                    <div class="layui-input-inline">
                        <div class="site-demo-upbar">
                            <input type="file" name="file[]" class="layui-upload-file" multiple="" id="images">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label  class="layui-form-label">缩略图
                    </label>

                    <div id="LAY_demo_upload">
                    {foreach $foodCity.imgUrl as $url}
                        <img id="" onClick="delImg(this, '<{$url}>')" width="80" src="<{$url}>">
                    {/foreach}
                    <!--<img id="LAY_demo_upload" width="400" src="/static/images/banner.png">-->
                    </div>

                </div>

                <div class="layui-form-item">
                    <label for="is_show" class="layui-form-label">
                        <span class="x-red">*</span>是否显示
                    </label>
                    <div class="layui-input-inline">
                        <input type="checkbox"  id="is_show" name="is_show" value="1"
                               {if condition="$foodCity.is_show == 1"}
                               checked=""
                               {else \}
                               {/if}
                               lay-skin="switch" lay-filter="switchTest" lay-text="1|0">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="is_hot" class="layui-form-label">
                        <span class="x-red">*</span>是否推荐
                    </label>
                    <div class="layui-input-inline">
                        <input type="checkbox"  id="is_hot" name="is_hot" value="1"
                               {if condition="$foodCity.is_hot == 1"}
                               checked=""
                               {else \}
                               {/if}
                               lay-skin="switch" lay-filter="switchTest" lay-text="1|0">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                    </label>
                    <button  class="layui-btn" lay-filter="add" lay-submit="">
                        修改
                    </button>
                </div>
            </form>
        </div>
        <script src="/static/lib/layui/layui.js" charset="utf-8">
        </script>
        <script src="/static/js/x-layui.js" charset="utf-8">
        </script>
        <script>
            layui.use(['form','layer','upload'], function(){
                $ = layui.jquery;
                var form = layui.form()
                    ,layer = layui.layer;
                layui.upload({
                    url: '<{:Url("admin/FoodCity/upload")}>' //上传接口
                    ,success: function(data){ //上传成功后的回调
                        var i = 0;
                        for(i=0;i<data.length;i++){
                            console.log(data[i]);
                            $img = '<img id="" width="100" style="padding-left:5px" onclick="delImg(this, '+ data[i]['filepath'] +')" src="'+ data[i]['file_path'] +'">';
                            $hidImg = '<input type="hidden" name="imgUrl[]" class="hidImg" onclick="delImg(this, '+ data[i]['filepath'] +')" value="'+ data[i]['file_path'] +'">';

                            $('#LAY_demo_upload').append($img);
                            $('#hidenImage').append($hidImg);
                        }
                    },
                    error: function() {
                        console.log('error');
                    }
                });
                //监听提交
//                form.on('submit(add)', function(data){
//                    console.log(data);
//                    //发异步，把数据提交给php
//                    layer.alert("增加成功", {icon: 6},function () {
//                        // 获得frame索引
//                        var index = parent.layer.getFrameIndex(window.name);
//                        //关闭当前frame
//                        parent.layer.close(index);
//                    });
//                    return false;
//                });
            });
            function delImg(obj, url) {
                var res = $('#hidenImage').children('.hidImg');
                for(i=0; i<res.length;i++){
                    if($(res[i]).attr('value') == $(obj).attr('src')){
                        // 移除该 img 和 hidImg
                        $(res[i]).remove();
                        $(obj).remove();
                    }
                }
            }
        </script>
        <script>
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
          var s = document.getElementsByTagName("script")[0]; 
          s.parentNode.insertBefore(hm, s);
        })();
        </script>
    </body>

</html>